package cn.org.eshow.webapp.action.h5;

import cn.org.eshow.bean.query.InfoQuery;
import cn.org.eshow.model.Info;
import cn.org.eshow.service.InfoManager;
import cn.org.eshow.webapp.action.BaseAction;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Results({@Result(name = "input", location = "add"),
        @Result(name = "list", type = "redirect", location = ""),
        @Result(name = "success", type = "redirect", location = "view/${id}"),
        @Result(name = "redirect", type = "redirect", location = "${redirect}")})
@AllowedMethods({"view", "browse", "list"})
public class InfoAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    @Autowired
    private InfoManager infoManager;

    private List<Info> infos;
    private Info info;
    private InfoQuery query = new InfoQuery(true);

    public String view(){
        if(id != null){
            info = infoManager.get(id);
        }
        return NONE;
    }

    public String browse(){
        info = infoManager.browse(query);
        return NONE;
    }

    public String list(){
        infos = infoManager.list(query);
        return LIST;
    }

    public List<Info> getInfos() {
        return infos;
    }

    public void setInfos(List<Info> infos) {
        this.infos = infos;
    }

    public Info getInfo() {
        return info;
    }

    public void setInfo(Info info) {
        this.info = info;
    }

    public InfoQuery getQuery() {
        return query;
    }

    public void setQuery(InfoQuery query) {
        this.query = query;
    }
}